package com.ruoyi.xxljob.admin.controller;

import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.xxljob.admin.service.XxlJobService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.Map;

/**
 * 运行报表相关
 *
 * @author wjialong
 */
@RestController
@RequestMapping("/report")
public class ReportInfoController {
    @Autowired
    XxlJobService xxlJobService;

    /**
     * 获取运行报表的基础数据
     *
     * @return
     */
    @RequiresPermissions("xxl-job:report:query")
    @GetMapping
    public AjaxResult getInfo() {
        Map<String, Object> ret = xxlJobService.dashboardInfo();
        return AjaxResult.success(ret);
    }

    /**
     * 获取运行报表的表格数据
     *
     * @param startTime
     * @param endTime
     * @return
     */
    @RequiresPermissions("xxl-job:report:query")
    @GetMapping("/chartInfo")
    public AjaxResult getChartInfo(@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date startTime,
                                   @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date endTime) {
        return xxlJobService.chartInfo(startTime, endTime);
    }
}
